package pers.mihao.quickstream.common.util;


public class IntegerUtil {


    public static int getRandomIn(int max) {
        return (int) (Math.floor(Math.random() * (max)));
    }

    public static String getRandomString(int length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append("9");
        }
        int value = getRandomIn(0, Integer.parseInt(sb.toString()));
        sb.setLength(0);
        while (String.valueOf(value).length() + sb.length() < length) {
            sb.append("0");
        }
        sb.append(value);
        return sb.toString();
    }

    public static Integer safeParseInt(String num){
        if (StringUtil.isNumber(num)) {
            return Integer.parseInt(num);
        }
        return null;
    }

    public static boolean isNum(String numString) {
        try {
            Integer.parseInt(numString);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public static int getRandomIn(int min, int max) {
        return (int) (Math.round(Math.random() * (max - min)) + min);
    }
}
